package com.zhiliao.enjoy.demo1;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者： zhi-liao
 * 类的作用:
 * 类的创建时间： 2021/5/23 17:56
 */
public class FlyweightFactory {

    private static Map flyweights = new HashMap<>();

    public FlyweightFactory(String arg) {
        flyweights.put(arg, new FlyweightImpl());
    }

    public static Flyweight getFlyweight(String key) {
        if (flyweights.get(key) == null) {
            flyweights.put(key, new FlyweightImpl());
        }
        return (Flyweight) flyweights.get(key);
    }
    public static int getSize() {
        return flyweights.size();
    }
}
